from flask import Flask
from app.model.base import db
from flask_login import LoginManager
from datetime import timedelta
login_manager = LoginManager()

def create_app():

    app = Flask(__name__)
    app.config.from_object('app.secure')
    app.config.from_object('app.setting')
    # 数据在浏览器缓存的时间：3分钟。三分钟之后调用视图函数返回浏览器中文件，而不重新获取数据
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = timedelta(seconds=3 * 60)
    register_blueprint(app)

    db.init_app(app)
    db.create_all(app=app)
    login_manager.init_app(app)
    login_manager.login_view = 'web.login'
    login_manager.login_message = '请先登录或注册'
    return app



def register_blueprint(app):
    from app.web.auth import web
    app.register_blueprint(web)


